package oracle.apps.financials.collection.po;

import java.util.Date;

import oracle.apps.financials.collection.util.MockDataFactory;

import com.j256.ormlite.dao.ForeignCollection;
import com.j256.ormlite.field.DataType;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.field.ForeignCollectionField;
import com.j256.ormlite.table.DatabaseTable;

@DatabaseTable(tableName = "c_customer")
public class Customer {


	public static final String COLLECTOR_ID_FIELD_NAME = "collectorID";
	public static final String CUSTOMER_ID = "customerID";

	@DatabaseField(generatedId = true)
	private Integer customerID;

	@DatabaseField(canBeNull = false, index = true, unique = true)
	private String customerName;

	@DatabaseField
	private String primaryContact;
	@DatabaseField
	private String businessLevel;
	@DatabaseField
	private String address;

	@DatabaseField(canBeNull = false)
	private String email;
	@DatabaseField(canBeNull = false)
	private String phone;
	@DatabaseField
	private String strategy;
	@DatabaseField
	private String note;

	private Metrics metrics;

	@ForeignCollectionField(eager = false,orderColumnName=MetricsItem.ITEM_TIME,columnName = MetricsItem.METRICS_ITEM_ID)//,orderColumnName=MetricsItem.ITEM_TIME,columnName = MetricsItem.METRICS_ITEM_ID)
	ForeignCollection<MetricsItem> metricsItemList;

	@ForeignCollectionField(eager = false)
	ForeignCollection<MetricsRaw> metricsRawList;

	@DatabaseField(canBeNull = true, foreign = true, foreignAutoRefresh = true, foreignAutoCreate = true, columnName = COLLECTOR_ID_FIELD_NAME)
	private Collector collector;

	@DatabaseField(dataType = DataType.DATE)
	private Date createTime = new Date();

	private MetricsItem currentMetricsItem;

	
	public Customer() {
		super();	
		collector = new Collector();		
	}

	public Metrics getMetrics() {
		if (metrics == null) {
			metrics = new Metrics();
			MockDataFactory.convertMetricsItems(this);
		}
		return metrics;
	}

	public String getCustomerName() {
		return customerName;
	}

	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}

	public String getPrimaryContact() {
		return primaryContact;
	}

	public void setPrimaryContact(String primaryContact) {
		this.primaryContact = primaryContact;
	}

	public String getBusinessLevel() {
		return businessLevel;
	}

	public void setBusinessLevel(String businessLevel) {
		this.businessLevel = businessLevel;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getStrategy() {
		return strategy;
	}

	public void setStrategy(String strategy) {
		this.strategy = strategy;
	}

	public void setMetrics(Metrics metrics) {
		this.metrics = metrics;
	}

	public Collector getCollector() {
		return collector;
	}

	public void setCollector(Collector collector) {
		this.collector = collector;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	public ForeignCollection<MetricsItem> getMetricsItemList() {
		return metricsItemList;
	}

	public void setMetricsItemList(ForeignCollection<MetricsItem> metricsItemList) {
		this.metricsItemList = metricsItemList;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Integer getCustomerID() {
		return customerID;
	}

	public void setCustomerID(Integer customerID) {
		this.customerID = customerID;
	}

	public ForeignCollection<MetricsRaw> getMetricsRawList() {
		return metricsRawList;
	}

	public void setMetricsRawList(ForeignCollection<MetricsRaw> metricsRawList) {
		this.metricsRawList = metricsRawList;
	}

	public MetricsItem getCurrentMetricsItem() {
		if (currentMetricsItem == null) {
			currentMetricsItem = new MetricsItem();
		}
		return currentMetricsItem;
	}

	public void setCurrentMetricsItem(MetricsItem currentMetricsItem) {
		this.currentMetricsItem = currentMetricsItem;
	}
}
